<?php
/**
Primary Author: Alex Arey
Updated: 3/28/2012

Handles DBTable for notes that administrators can add to courses and community partners

*/
class Application_Model_DbTable_Notes extends Zend_Db_Table_Abstract {

	protected $_name = 'NOTES';

	public function addPartnerNote($partnerID, $content){
		$this->insert(array(
			'ID'=>$this->getNextKey(),
			'CONTENT_ID'=>$partnerID,
			'TYPE'=>'PARTNER',
			'CONTENT'=>$content
		));
	}
	public function updatePartnerNote($partnerID, $content){
		if($this->getPartnerNote($partnerID)!=""){
			$this->update(array('CONTENT'=>$content), 'CONTENT_ID='.$partnerID.' and TYPE=\'PARTNER\'');
		}else{
			$this->addPartnerNote($partnerID, $content);
		}
	}
	public function deletePartnerNote($partnerID){
		$this->delete('CONTENT_ID='.$partnerID.' and TYPE=\'PARTNER\'');
	}
	public function getPartnerNote($partnerID){
		$row = $this->fetchRow('CONTENT_ID='.$partnerID.' and TYPE=\'PARTNER\'');
		if(!$row){
			return "";
		}
		return $row['CONTENT'];
	}
	public function addCourseNote($courseID, $content){
	
	}
	public function updatecourseNote( $courseID){
	
	}
	public function deletecourseNote($courseID){
	
	}
	public function getcourseNote($courseID){
	
	}
	
	public function getNextKey(){
		$sqlquery = $this->select()->from($this->_name, array("MAX(ID)"));
		$insertrow = $this->fetchRow($sqlquery)->toArray();
		return $insertrow["MAX(ID)"] + 1;
	
	}
}
	/*
	 ID - NUMBER, PK, NOT NULL
	CONTENT_ID - NUMBER
	TYPE - VARCHAR2, 20
	CONTENT - VARCHAR2, 1024
	*/
?>